; Music of TT Racer (1986) (Digital Integration Ltd.)
; Ripped by Megachur the 16/11/2006

	write "TTRACER.BIN"

music_date_rip	equ &10b6
music_adr	equ &2a6b
first_theme	equ 0
last_theme	equ 3

	read "music_header_v1_0.asm"

.l2a6b
	db &00
.l2a6c
	ld hl,l2a6b
	dec (hl)
	ret nz
	ld (hl),#06
;
.play_music
;
	push bc
	push de
	push hl
	push ix
	ld b,#02
	ld c,#00
	ld hl,l2bf2
	ld de,l2bf4
.l2a82
	ld a,(de)
	cp (hl)
	ld a,c
	call c,l2aef
	ld a,(hl)
	ld (de),a
	inc hl
	inc de
	inc c
	djnz l2a82
	ld b,#02
	ld hl,l2bf2
.l2a94
	ld a,(hl)
	and a
	jr nz,l2aa1
	inc hl
	djnz l2a94
	call l2b27
	jp l2ae9
.l2aa1
	ld ix,#0000
	call l2b5f
	ld ix,#0001
	call l2b5f
	ld hl,(#9ea1)
	inc hl
	ld (#9ea3),hl
	ld a,(#9ea8)
	ld (#9ea9),a
	ld hl,#0058
	ld de,#0054
	ld a,(de)
	cp (hl)
	jr nc,l2ae3
	inc hl
	inc de
	ld a,(de)
	cp (hl)
	jr nc,l2ae3
	ld a,(l2bf6)
	and a
	jr nz,l2ad7
	call l2b27
	jr l2ae9
.l2ad7
	ld b,#02
	ld hl,l2bf4
.l2adc
	ld (hl),#00
	inc hl
	djnz l2adc
	jr l2ae9
.l2ae3
	ld hl,#9e9f
	call l9e74
.l2ae9
	pop ix
	pop hl
	pop de
	pop bc
	ret
;
.init_music
.l2aef
;
	push bc
	push de
	push hl
	ld c,a
	ld b,#00
	ld hl,l2bf2
	add hl,bc
	ld b,#02
	ld a,#00
	ld de,l2bf4
.l2b00
	ld (de),a
	inc de
	djnz l2b00
	ld (hl),#ff
	sla c
	sla c
	sla c
	ld b,#00
	ld hl,l2bf7
	ld de,#0050
	add hl,bc
	ld bc,#0008
	ldir
	ld hl,#0000
	ld (#0058),hl
	ld (#0060),hl
	pop hl
	pop de
	pop bc
	ret
;
.stop_music
.l2b27
;
	push bc
	push de
	push hl
	ld hl,#0000
	ld (#9e9f),hl
	ld (#9ea1),hl
	ld (#9ea3),hl
	ld a,#00
	ld (#9ea5),a
	ld a,#38
	ld (#9ea6),a
	ld hl,#9e9f
	call l9e74
	ld a,#00
	ld b,#02
	ld hl,l2bf2
	ld de,l2bf4
.l2b50
	ld (hl),a
	ld (de),a
	inc hl
	inc de
	djnz l2b50
	ld a,#00
	ld (l2bf6),a
	pop hl
	pop de
	pop bc
	ret
.l2b5f
	ld a,(ix+#60)
	and a
	jr nz,l2b96
	call l2bad
	ld a,(ix+#5e)
	ld (ix+#60),a
	ld a,(#005a)
	ld (#9e9f),a
	ld a,(#005c)
	ld (#9ea0),a
	ld a,(#005b)
	ld (#9ea1),a
	ld a,(#005d)
	ld (#9ea2),a
	inc (ix+#58)
	dec (ix+#60)
	ld de,#9e9f
	add ix,de
	ld (ix+#08),#0d
	ret
.l2b96
	dec (ix+#60)
	ld a,(ix+#60)
	and #07
	ret nz
	ld de,#9e9f
	add ix,de
	ld a,(ix+#08)
	and a
	ret z
	dec (ix+#08)
	ret
.l2bad
	push bc
	push de
	push hl
	ld c,(ix+#58)
	ld b,#00
	ld l,(ix+#50)
	ld h,(ix+#52)
	add hl,bc
	ld a,(hl)
	ld e,a
	and #1f
	jr z,l2bc5
	add (ix+#56)
.l2bc5
	sla a
	ld c,a
	ld b,#00
	ld hl,l2d16
	add hl,bc
	ld a,(hl)
	ld (ix+#5a),a
	inc hl
	ld a,(hl)
	ld (ix+#5c),a
	ld a,e
	and #e0
	srl a
	srl a
	srl a
	srl a
	srl a
	inc a
	ld d,a
	sla a
	sla a
	add d
	ld (ix+#5e),a
	pop hl
	pop de
	pop bc
	ret
.l2bf7 equ $ + 5
.l2bf6 equ $ + 4
.l2bf4 equ $ + 2
.l2bf2
	db #00,#00,#00,#00,#00,#07,#20,#2c
	db #2c,#19,#19,#0e,#02,#39,#ce,#2c
	db #2c,#95,#48,#0e,#02,#0f,#0a,#06
	db #0a,#0f,#0a,#06,#0a,#12,#0d,#0a
	db #0d,#12,#0d,#0a,#0d,#11,#0d,#0a
	db #0d,#11,#0d,#0a,#0d,#ef,#03,#06
	db #0a,#0f,#03,#06,#0a,#0f,#06,#0a
	db #0d,#12,#06,#0a,#0d,#12,#0a,#0d
	db #11,#16,#0a,#0d,#11,#16,#ef,#11
	db #0f,#0d,#00,#05,#03,#01,#00,#0f
	db #11,#32,#12,#16,#34,#11,#0f,#0d
	db #00,#0d,#0c,#0d,#0f,#11,#12,#af
	db #12,#14,#16,#00,#16,#12,#31,#12
	db #14,#18,#16,#14,#18,#19,#18,#16
	db #14,#32,#2f,#28,#0a,#0c,#ad,#11
	db #0f,#0d,#00,#0a,#09,#2a,#0c,#0d
	db #0f,#0d,#0c,#0f,#2d,#0a,#0c,#0d
	db #0c,#0a,#0d,#0c,#0a,#09,#0c,#aa
	db #0f,#11,#12,#00,#0f,#0e,#2f,#11
	db #12,#14,#12,#0f,#0e,#2f,#12,#14
	db #16,#12,#0f,#12,#11,#0f,#0e,#11
	db #af,#11,#0f,#0d,#00,#05,#03,#01
	db #00,#0f,#11,#32,#12,#16,#34,#11
	db #0f,#0d,#00,#0d,#0c,#0d,#0f,#11
	db #12,#af,#12,#14,#16,#00,#16,#12
	db #31,#12,#14,#18,#16,#14,#18,#19
	db #18,#16,#14,#12,#11,#0f,#0d,#0a
	db #08,#0a,#0c,#ad,#31,#6d,#68,#66
	db #6d,#31,#32,#74,#52,#11,#2f,#31
	db #32,#36,#74,#6f,#6d,#2f,#32,#2a
	db #2f,#4d,#08,#2a,#31,#56,#14,#32
	db #31,#6c,#6a,#25,#2d,#28,#2c,#4a
	db #0c,#2d,#2a,#6f,#6a,#72,#6a,#2f
	db #2a,#28,#2a,#4f,#11,#32,#34,#6d
	db #68,#66,#6d,#31,#32,#74,#52,#11
	db #2f,#31,#32,#36,#74,#6f,#6d,#2f
.l2d16 equ $ + 4
	db #32,#2c,#2f,#ad,#00,#00
	dw #01de,#01c3,#01aa,#0192
	dw #017b,#0166,#0152,#013f
	dw #012d,#011c,#010c,#00fd
	dw #00ef,#00e1,#00d5,#00c9
	dw #00be,#00b3,#00a9,#009f
	dw #0096,#008e,#0086,#007f
	dw #0077,#0071,#006a,#0064
	dw #005f,#0059,#0054,#0050
	dw #004b,#0047,#0043,#003f
	dw #003c,#0038,#0035,#0032
	dw #002f,#002d,#002a,#0028
	dw #0026,#0024,#0022,#0020
	dw #001e,#001c,#001b,#0019
	dw #0018,#0016,#0015,#0014
	dw #0013,#0012,#0011,#0010
	
	
;	org #9e74
.l9e74
	push af
	push bc
	push de
	push hl
	ld b,#f7
	ld a,#82
	out (c),a
	ld e,#00
.l9e80
	ld d,(hl)
	inc hl
	call l9ebb
	inc e
	ld a,e
	cp #0e
	jr c,l9e80
	ld a,#0e
	ld b,#f4
	out (c),a
	ld b,#f6
	ld a,#c0
	out (c),a
	xor a
	out (c),a
	pop hl
	pop de
	pop bc
	pop af
	ret
	db #50,#00,#8e,#00,#8f,#00,#00,#38
	db #0c,#0a,#0a
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#38,#00,#00,#00,#00,#00
	db #00
.l9ebb
	ld b,#f4
	out (c),e
	ld b,#f6
	ld a,#c0
	out (c),a
	xor a
	out (c),a
	ld b,#f4
	out (c),d
	ld b,#f6
	ld a,#80
	out (c),a
	xor a
	out (c),a
	ret

; init &2aef
; play &2a6c	x 6
; stop &2b27

;org #6580
;.l6580
;call #2b27
;ld a,#ff
;ld (#2bf3),a
;ld (#2bf6),a
;call #3cff
;call #2b27
;call #398e
;ld a,(#0ea2)
;rla
;jr c,l6580
;call #3222
;di
;ld hl,#3215
;ld (#0039),hl
;jr l6580

.game_name
	db "TT Racer",0
.game_year
	db "1986",0
.game_publisher
	db "Digital Integration Ltd.",0
.music_author
	db "",0
.music_comment
	db "",0

	read "music_end_v1_0.asm"
